const { query } = require("../db");

const _GET = async (ctx, next) => {
  const { key = undefined } = ctx.request.query;
  const SQL = `SELECT * FROM lottery WHERE id = '${key}'`;
  let result = await query(SQL);
  if (result.length > 0) {
    const { status } = result[0];
    if (status === 1) {
      const _sql = `UPDATE lottery SET status = 0 WHERE id = '${key}'`;
      const _res = await query(_sql);
    }
  }
  ctx.response.body = result;
};

module.exports = {
  _GET
};
